/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @signatureAlgorithm = 'v2';
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('metaspace', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ApplyCoordinationWithCodeRequest {
  coordinationCode?: string(name='CoordinationCode', example='PA3MU***'),
  loginRegionId?: string(name='LoginRegionId', example='cn-hangzhou'),
  loginToken?: string(name='LoginToken', example='v2c4e2ef03d62******'),
  sessionId?: string(name='SessionId', example='09e2b2e6-3181******'),
  uuid?: string(name='Uuid', example='A8B35215993FBF283F28D61******'),
}

model ApplyCoordinationWithCodeResponseBody = {
  data?: {
    coId?: string(name='CoId', example='co-0ad0f3p4n2******'),
    coordinateStatus?: string(name='CoordinateStatus', example='COORDINATING'),
    coordinateTicket?: string(name='CoordinateTicket', example='DQpbRGVza3RvcF0NCkZvcmNlVGxzVHlwZT0xDQ******'),
    coordinatorAliUid?: long(name='CoordinatorAliUid', example='1126819517******'),
    coordinatorUserId?: string(name='CoordinatorUserId', example='bob'),
    ownerAliUid?: long(name='OwnerAliUid', example='1126819517******'),
    ownerUserId?: string(name='OwnerUserId', example='alice'),
    resourceId?: string(name='ResourceId', example='ecd-3vv4mf8zxg******'),
    resourceName?: string(name='ResourceName', example='demo-desktop'),
    resourceRegionId?: string(name='ResourceRegionId', example='cn-hangzhou'),
    resourceType?: string(name='ResourceType', example='CloudDesktop'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='AD2D0761-1FE5-549D-B169******'),
}

model ApplyCoordinationWithCodeResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ApplyCoordinationWithCodeResponseBody(name='body'),
}

/**
 * @summary 用协同码发起协同
 *
 * @param request ApplyCoordinationWithCodeRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ApplyCoordinationWithCodeResponse
 */
async function applyCoordinationWithCodeWithOptions(request: ApplyCoordinationWithCodeRequest, runtime: Util.RuntimeOptions): ApplyCoordinationWithCodeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.coordinationCode)) {
    body['CoordinationCode'] = request.coordinationCode;
  }
  if (!Util.isUnset(request.loginRegionId)) {
    body['LoginRegionId'] = request.loginRegionId;
  }
  if (!Util.isUnset(request.loginToken)) {
    body['LoginToken'] = request.loginToken;
  }
  if (!Util.isUnset(request.sessionId)) {
    body['SessionId'] = request.sessionId;
  }
  if (!Util.isUnset(request.uuid)) {
    body['Uuid'] = request.uuid;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ApplyCoordinationWithCode',
    version = '2022-03-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'Anonymous',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 用协同码发起协同
 *
 * @param request ApplyCoordinationWithCodeRequest
 * @return ApplyCoordinationWithCodeResponse
 */
async function applyCoordinationWithCode(request: ApplyCoordinationWithCodeRequest): ApplyCoordinationWithCodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return applyCoordinationWithCodeWithOptions(request, runtime);
}

model EndAllCoordinationByOwnerRequest {
  loginRegionId?: string(name='LoginRegionId', example='cn-hangzhou'),
  loginToken?: string(name='LoginToken', example='v2c4e2ef03d62******'),
  resourceId?: string(name='ResourceId', example='ecd-68a7ddrt0******'),
  resourceRegionId?: string(name='ResourceRegionId', example='cn-hangzhou'),
  resourceType?: string(name='ResourceType', example='CloudDesktop'),
  sessionId?: string(name='SessionId', example='09e2b2e6-3181******'),
}

model EndAllCoordinationByOwnerResponseBody = {
  requestId?: string(name='RequestId', example='AD2D0761-1FE5-549D-B169******'),
}

model EndAllCoordinationByOwnerResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EndAllCoordinationByOwnerResponseBody(name='body'),
}

/**
 * @summary Owner主动结束本次协同，同步失效协同码
 *
 * @param request EndAllCoordinationByOwnerRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return EndAllCoordinationByOwnerResponse
 */
async function endAllCoordinationByOwnerWithOptions(request: EndAllCoordinationByOwnerRequest, runtime: Util.RuntimeOptions): EndAllCoordinationByOwnerResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.loginRegionId)) {
    body['LoginRegionId'] = request.loginRegionId;
  }
  if (!Util.isUnset(request.loginToken)) {
    body['LoginToken'] = request.loginToken;
  }
  if (!Util.isUnset(request.resourceId)) {
    body['ResourceId'] = request.resourceId;
  }
  if (!Util.isUnset(request.resourceRegionId)) {
    body['ResourceRegionId'] = request.resourceRegionId;
  }
  if (!Util.isUnset(request.resourceType)) {
    body['ResourceType'] = request.resourceType;
  }
  if (!Util.isUnset(request.sessionId)) {
    body['SessionId'] = request.sessionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EndAllCoordinationByOwner',
    version = '2022-03-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'Anonymous',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Owner主动结束本次协同，同步失效协同码
 *
 * @param request EndAllCoordinationByOwnerRequest
 * @return EndAllCoordinationByOwnerResponse
 */
async function endAllCoordinationByOwner(request: EndAllCoordinationByOwnerRequest): EndAllCoordinationByOwnerResponse {
  var runtime = new Util.RuntimeOptions{};
  return endAllCoordinationByOwnerWithOptions(request, runtime);
}

model GenerateCoordinationCodeRequest {
  loginRegionId?: string(name='LoginRegionId', example='cn-hangzhou'),
  loginToken?: string(name='LoginToken', example='v2c4e2ef03d62******'),
  resourceId?: string(name='ResourceId', example='ecd-68a7ddrt0******'),
  resourceName?: string(name='ResourceName', example='demo-desktop'),
  resourceRegionId?: string(name='ResourceRegionId', example='cn-hangzhou'),
  resourceType?: string(name='ResourceType', example='CloudDesktop'),
  sessionId?: string(name='SessionId', example='09e2b2e6-3181******'),
}

model GenerateCoordinationCodeResponseBody = {
  coordinationCode?: string(name='CoordinationCode', example='PA3MU***'),
  requestId?: string(name='RequestId', example='AD2D0761-1FE5-549D-B169******'),
}

model GenerateCoordinationCodeResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GenerateCoordinationCodeResponseBody(name='body'),
}

/**
 * @summary 生成协同码
 *
 * @param request GenerateCoordinationCodeRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GenerateCoordinationCodeResponse
 */
async function generateCoordinationCodeWithOptions(request: GenerateCoordinationCodeRequest, runtime: Util.RuntimeOptions): GenerateCoordinationCodeResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.loginRegionId)) {
    body['LoginRegionId'] = request.loginRegionId;
  }
  if (!Util.isUnset(request.loginToken)) {
    body['LoginToken'] = request.loginToken;
  }
  if (!Util.isUnset(request.resourceId)) {
    body['ResourceId'] = request.resourceId;
  }
  if (!Util.isUnset(request.resourceName)) {
    body['ResourceName'] = request.resourceName;
  }
  if (!Util.isUnset(request.resourceRegionId)) {
    body['ResourceRegionId'] = request.resourceRegionId;
  }
  if (!Util.isUnset(request.resourceType)) {
    body['ResourceType'] = request.resourceType;
  }
  if (!Util.isUnset(request.sessionId)) {
    body['SessionId'] = request.sessionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GenerateCoordinationCode',
    version = '2022-03-07',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'Anonymous',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 生成协同码
 *
 * @param request GenerateCoordinationCodeRequest
 * @return GenerateCoordinationCodeResponse
 */
async function generateCoordinationCode(request: GenerateCoordinationCodeRequest): GenerateCoordinationCodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return generateCoordinationCodeWithOptions(request, runtime);
}

